package com.ruike.alisurface.utils;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.hjq.xtoast.XToast;
import com.ruike.alisurface.R;
import com.voodoo.lib_utils.DeviceUtils;

public class DialogTipUtils {

    public static XToast xToast;

    public static void showTipDialog(Context context, View.OnClickListener confirm_tvLinister) {

        View toastView = LayoutInflater.from(context).inflate(R.layout.item_dialog_tip, null);

        TextView confirm_tv = toastView.findViewById(R.id.dialog_confirm_tv);
        TextView cancal_tv = toastView.findViewById(R.id.dialog_cancal_tv);
        xToast = new XToast((Activity) context).setView(toastView).setAnimStyle(android.R.style.Animation_Toast).setBackgroundDimAmount(0.6f);
        xToast.setWidth(PxUtils.dp2px(context, 800));
        xToast.setHeight(PxUtils.dp2px(context, 500));
        xToast.setYOffset(PxUtils.dp2px(context, 500));
        xToast.setOutsideTouchable(false);
        xToast.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL);
        xToast.show();
        confirm_tv.setOnClickListener(confirm_tvLinister);
        cancal_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xToast.cancel();
            }
        });
    }

    public static void showTipDialog(Context context, String msg, View.OnClickListener confirm_tvLinister) {

        View toastView = LayoutInflater.from(context).inflate(R.layout.item_dialog_tip, null);
        TextView dialog_msg_tv = toastView.findViewById(R.id.dialog_msg_tv);
        dialog_msg_tv.setText(msg);
        TextView confirm_tv = toastView.findViewById(R.id.dialog_confirm_tv);
        TextView cancal_tv = toastView.findViewById(R.id.dialog_cancal_tv);
        xToast = new XToast((Activity) context).setView(toastView).setAnimStyle(android.R.style.Animation_Toast).setBackgroundDimAmount(0.6f);

        xToast.setWidth(PxUtils.dp2px(context, 800));
        xToast.setHeight(PxUtils.dp2px(context, 500));
        xToast.setYOffset(PxUtils.dp2px(context, 500));
        xToast.setOutsideTouchable(false);
        xToast.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL);
        xToast.show();
        confirm_tv.setOnClickListener(confirm_tvLinister);
        cancal_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xToast.cancel();
            }
        });
    }

    public static void setErrorDialog(Context context) {

        View toastView = LayoutInflater.from(context).inflate(R.layout.item_dialog, null);

        TextView textView = toastView.findViewById(R.id.dialog_confirm_tv);
        XToast xToast = new XToast((Activity) context).setView(toastView).setAnimStyle(android.R.style.Animation_Toast).setBackgroundDimAmount(0.6f);
        xToast.setWidth(PxUtils.dp2px(context, 800));
        xToast.setHeight(PxUtils.dp2px(context, 440));
        xToast.setYOffset(PxUtils.dp2px(context, 500));
        xToast.setOutsideTouchable(false);
        xToast.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL);
        xToast.show();
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                xToast.cancel();
            }
        });

    }
}
